package com.ht.WeNas.data.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ht.WeNas.data.dto.UserDto;
import com.ht.WeNas.data.enumObj.UserType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Objects;

@Data
@TableName("tb_user")
@Schema(description = "用户数据")
public class User {
    @Schema(description = "用户id")
    Long id;

    @Schema(description = "用户名")
    String username;

    @Schema(description = "用户密码")
    String password;

    @Schema(description = "用户类型")
    UserType userType;

    @Schema(description = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    LocalDateTime createTime;

    @Schema(description = "更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    LocalDateTime updateTime;

    public User() {}
    
    public User(UserDto dto) {
        this.id = Long.valueOf(dto.getId());
        this.username = dto.getUsername();
        this.userType = dto.getUserType();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return Objects.equals(id, user.id) && Objects.equals(username, user.username) && Objects.equals(password, user.password) && userType == user.userType;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, username, password, userType);
    }
}
